﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Home : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["User_ID"] = null;
        Session["role"] = null;

        //弹出窗口
        //Response.Write("<script language=javascript>alert('请登录系统!')</script>");
    }

    protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
    {
        e.Authenticated = false;
        string str = ConfigurationManager.ConnectionStrings["DevMgmntConnectionString"].ConnectionString.ToString();
        SqlConnection con = new SqlConnection(str);
        con.Open();
        string userlogin1 = "select sRole from t_admin where sName ='" + ctlLogin.UserName + "'and sPassword='" + ctlLogin.Password + "'";
        SqlDataAdapter da = new SqlDataAdapter(userlogin1, con);
        DataSet ds = new DataSet();
        int count = da.Fill(ds, "table");
        if (count > 0)//登录成功
        {
            //将用户名存放到session中    
              e.Authenticated = true;//通过验证 
              Session["User_ID"] = ctlLogin.UserName;
              Session["role"] = ds.Tables[0].Rows[0].ItemArray[0];
        }
 
        con.Close();
    }



    protected void OnLoggedIn(object sender, EventArgs e)
    {
        Response.Redirect("viewrecordlist.aspx");
    }


}